package src.leetcode.dp.medium_0279;

public class numSquares {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.numSquares(12));
    }
}

class Solution {
    public int numSquares(int n) {
        int []dp = new int[n + 1];

        for(int i = 1; i * i <= n; i++){
            for (int j = i * i; j <= n; j++){
                if (dp[j] == 0) dp[j] = dp[j - i * i] + 1;
                else dp[j] = Math.min(dp[j], dp[j - i * i] + 1);
            }
        }

        return dp[n];
    }
}
